<?php

require("./mpcamera/setup.php");

$smarty = new Smarty_MPCamera();

$submit = filter_input(INPUT_POST, "btnSubmit");
$username = filter_input(INPUT_POST, "txtUserName");
$password = filter_input(INPUT_POST, "txtPassword");

if (!empty($submit)) {
    $query = "
        SELECT `Username` FROM `user`
        WHERE 
            `Username`='$username' 
        AND 
            `Password` = MD5('$password');
    ";

    $result = mysql_query($query);

    if (mysql_num_rows($result) != 1) {
        $smarty->assign("error", 1);
    } else {
        $data = mysql_fetch_array($result);
        $_SESSION["username"] = $data["Username"];
        $smarty->assign("username", $_SESSION["username"]);
        header("Location: /");
        die();
    }
}

$smarty->display("login.tpl");

